package com.ml.util;

import java.util.Calendar;
import java.util.Date;

/**
 * 获取当月的最大天数
 *  @Time 2019年6月14日 10:37:31
 *  @Author zzy
 */
public class UtilMonthMaxDay {
    /**
     * 获得某个月最大天数
     * @param year 年份
     * @param month 月份 (1-12)
     * @return 某个月最大天数
     */
    public  static int getMaxDayByYearMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year );
        //Calendar 的月份取值范围是 0 - 11 ， 0代表1月 11代表12月份
        month = month - 1 ;
        calendar.set(Calendar.MONTH, month);
        return calendar.getActualMaximum(Calendar.DATE);
}



    /**根据date获取*/
    public static int getMaxDayByYearMonth(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DATE);
    }




    /**根据date获取星期几*/
    public static String getWeekDay(Date date){
        //获取当前星期几
        Calendar calendar;
        calendar = Calendar.getInstance();
        if(date!=null){
            calendar.setTime(date);
        }
        ///System.out.println("当前月份："+calendar.DAY_OF_MONTH);
        String week;
        week = calendar.get(calendar.DAY_OF_WEEK) - 1 + "";
        if ("0".equals(week)) {
            week = "7";
        }
        week = "星期"+"一二三四五六日".charAt(Integer.valueOf(week)-1);
        return week;
    }




    public static void main(String args[]){

        System.out.println( getWeekDay(null)  );
    }



}
